Skip to content

PHPC-752: Add maxStalenessMS to ReadPreference class #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 19, 2016

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Sep 12, 2016

https://jira.mongodb.org/browse/PHPC-752

I was premature in signing off on #380, as it was lacking support for maxStalenessMS on the ReadPreference object. This adds a new constructor argument, getter method, and adds "maxStalenessMS" to the ReadPreference debug output.

var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY, array(array("tag" => "one"))));
var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY, array()));
var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY, [['tag' => 'one']]));
var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY, []));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just array() to [] refactoring here. Since this is the only ReadPreference constructor test, I added a new case for "maxStalenessMS" below; however, it's probably redundant in light of the ReadPreference::getMaxStalenessMS() test.

@@ -46,21 +46,22 @@ PHONGO_API zend_class_entry *php_phongo_readpreference_ce;

zend_object_handlers php_phongo_handler_readpreference;

/* {{{ proto void ReadPreference::__construct(integer $mode[, array $tagSets = array()])
/* {{{ proto void ReadPreference::__construct(integer $mode[, array $tagSets = array()[, integer $maxStalenessMS]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would much rather see this being an options array, as it is possible that other options might be added in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll refactor this to expect an options array and check a "maxStalenessMS" value.

@@ -1,5 +1,5 @@
--TEST--
MongoDB\Driver\ReadPreference::getMode()
MongoDB\Driver\ReadPreference::getTagSets()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit doesn't really belong here, perhaps in #399.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a stand-alone commit akin to any typo fix. The PR should make no difference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to #408.

@jmikola jmikola force-pushed the phpc-752 branch 5 times, most recently from 8e37c11 to 8bb7d70 Compare September 15, 2016 20:18
case 2:
if (tagSets) {
bson_t *tags = bson_new();
if (tagSets) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I removed the switch statement and am processing tagSets first, I added a test that tag set exceptions are thrown before maxStalenessMS.

@@ -0,0 +1,54 @@
--TEST--
MongoDB\Driver\Manager::__construct(): read preference options of the wrong type are ignored
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to change this behavior in the future, but this is how processing of Manager options operates today. We can revise this test if we decide to change this in the future.

I'll note that mongoc-uri.c is also quite lax about type errors. For instance, options that are expected to be integers are run through strtol() with no error handling.

@@ -1,13 +0,0 @@
--TEST--
MongoDB\Driver\Manager: maxStalenessMS
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was essentially renamed to manager-ctor-read_preference-002.phpt, where I added an additional test case and assert the state of Manager::getReadPreference().

@@ -1,33 +0,0 @@
--TEST--
MongoDB\Driver\Manager: maxStalenessMS
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was renamed to manager-ctor-read_preference-error-002.phpt, where I added an additional error case for an out-of-range value.

Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except for the inclusion of maxStalenessMS in debug output when it's not set, or using the default.

--EXPECTF--
object(MongoDB\Driver\ReadPreference)#%d (%d) {
["mode"]=>
int(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to fail/create conflicts after the PHPC-498 changes (ReadPreference, ReadConcern, and WriteConcern value).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that because you're changing it to display the string name? If so, you can easily update this when PHPC-489 is implemented.

I have absolutely no reservations whatever about going back and modifying tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it turns into a string. I'll do the PHPC-489 tomorrow (Monday), should be ready for you to review when you wake up.

@@ -982,6 +982,8 @@ void php_phongo_read_preference_to_zval(zval *retval, const mongoc_read_prefs_t
} else {
ADD_ASSOC_NULL_EX(retval, "tags");
}

ADD_ASSOC_LONG_EX(retval, "maxStalenessMS", mongoc_read_prefs_get_max_staleness_ms(read_prefs));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be added if maxstaleness is the default (0), just like we're no longer to do that for "journal", "w", etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

array(0) {
}
["maxStalenessMS"]=>
int(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be excluded here (As mentioned in an earlier comments).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@jmikola jmikola force-pushed the phpc-752 branch 2 times, most recently from 2b62d20 to a9e9776 Compare September 16, 2016 14:06
@@ -963,7 +963,7 @@ void php_phongo_read_preference_to_zval(zval *retval, const mongoc_read_prefs_t
{
const bson_t *tags = mongoc_read_prefs_get_tags(read_prefs);

array_init_size(retval, 2);
array_init_size(retval, 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess using 3 when there are only 2 items is fine, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just controls the initial HashTable size, so it should be fine. The buckets are still empty until we fill them.

@jmikola jmikola merged commit 6ec5348 into mongodb:master Sep 19, 2016
jmikola added a commit that referenced this pull request Sep 19, 2016
@jmikola jmikola deleted the phpc-752 branch September 19, 2016 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants